# CMFCore imports
from Products.CMFCore import utils as cmfutils

# Archetypes imports
from Products.Archetypes.atapi import *
from Products.Archetypes import listTypes

# iqpp.plone.guestbook imports
from iqpp.plone.guestbook.config import PROJECTNAME
from iqpp.plone.guestbook.config import ADD_CONTENT_PERMISSIONS

def initialize(context):
    """Intializer called when used as a Zope 2 product.
    """
    # imports packages and types for registration
    from content import *    
    
    # initialize portal content
    content_types, constructors, ftis = process_types(
        listTypes(PROJECTNAME),
        PROJECTNAME)
    
    cmfutils.ContentInit(
        PROJECTNAME + ' Content',
        content_types      = content_types,
        permission         = "Add portal content",
        extra_constructors = constructors,
        fti                = ftis,
        ).initialize(context)
        
    # Give it some extra permissions to control them on a per class limit
    for i in range(0,len(content_types)):
        klassname=content_types[i].__name__
        if not klassname in ADD_CONTENT_PERMISSIONS:
            continue

        context.registerClass(meta_type   = ftis[i]['meta_type'],
                              constructors= (constructors[i],),
                              permission  = ADD_CONTENT_PERMISSIONS[klassname])